'use strict';
module.exports = {
	/**
	 * 仅获取课程信息
	 * @url client/course/pub/only_course_detail 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid,type, _id } = data;
		let res = { code: 0, msg: "", data: {} };
		// 业务逻辑开始-----------------------------------------------------------
		//课程主体
		res.data.courses = await vk.baseDao.findById({
			dbName:type=='course'?'course':'live_course',
			id: data._id,
			whereJson: {
				is_show: 1,
				published_at: _.lte(pubFun.getNowTimeStr())
			}
		});

		res.data.test = await vk.baseDao.selects({
			dbName: "course_chapter",
			getMain: true,
			pageSize: 9999,
			whereJson: { course_id: data._id },
			// 视频
			foreignDB: [{
				dbName:type=='course'?"course_videos":"live_course_videos",
				localKey: "_id",
				foreignKey: "chapter_id",
				as: "videos",
				whereJson: { course_id: data._id, is_show: 1 },
				sortArr: [{ "name": "sort", "type": "desc" }],
				// 观看情况
				foreignDB: [{
					dbName: "user_video_watch_records",
					localKey: "_id",
					foreignKey: "video_id",
					as: "watch_info",
					limit: 1,
					fieldJson: { _id: true },
				}]
			}]
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
